package com.ruoyi.crm.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.crm.domain.CrmExpertPool;
import com.ruoyi.crm.service.ICrmExpertPoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 专家库Controller
 *
 * @author yanwenliang
 * @date 2024-08-15
 */
@RestController
@RequestMapping("/crm/expert")
public class CrmExpertPoolController extends BaseController
{
    @Autowired
    private ICrmExpertPoolService crmExpertPoolService;

    /**
     * 查询专家库列表
     */
    @PreAuthorize("@ss.hasPermi('crm:expert:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmExpertPool crmExpertPool)
    {
        startPage();
        List<CrmExpertPool> list = crmExpertPoolService.selectCrmExpertPoolList(crmExpertPool);
        return getDataTable(list);
    }

    /**
     * 导出专家库列表
     */
    @PreAuthorize("@ss.hasPermi('crm:expert:export')")
    @Log(title = "专家库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmExpertPool crmExpertPool)
    {
        List<CrmExpertPool> list = crmExpertPoolService.selectCrmExpertPoolList(crmExpertPool);
        ExcelUtil<CrmExpertPool> util = new ExcelUtil<CrmExpertPool>(CrmExpertPool.class);
        util.exportExcel(response, list, "专家库数据");
    }

    /**
     * 获取专家库详细信息
     */
    @PreAuthorize("@ss.hasPermi('crm:expert:query')")
    @GetMapping(value = "/{expertId}")
    public AjaxResult getInfo(@PathVariable("expertId") Long expertId)
    {
        return AjaxResult.success(crmExpertPoolService.selectCrmExpertPoolByExpertId(expertId));
    }

    /**
     * 新增专家库
     */
    @PreAuthorize("@ss.hasPermi('crm:expert:add')")
    @Log(title = "专家库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmExpertPool crmExpertPool)
    {
        return toAjax(crmExpertPoolService.insertCrmExpertPool(crmExpertPool));
    }

    /**
     * 修改专家库
     */
    @PreAuthorize("@ss.hasPermi('crm:expert:edit')")
    @Log(title = "专家库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmExpertPool crmExpertPool)
    {
        return toAjax(crmExpertPoolService.updateCrmExpertPool(crmExpertPool));
    }

    /**
     * 删除专家库
     */
    @PreAuthorize("@ss.hasPermi('crm:expert:remove')")
    @Log(title = "专家库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{expertIds}")
    public AjaxResult remove(@PathVariable Long[] expertIds)
    {
        return toAjax(crmExpertPoolService.deleteCrmExpertPoolByExpertIds(expertIds));
    }

    /**
     * 获取全部专家信息
     * @param crmExpertPool
     * @return
     */
    @PostMapping("/getExpertList")
    public AjaxResult getExpertList(@RequestBody(required = false) CrmExpertPool crmExpertPool){
        return AjaxResult.success(crmExpertPoolService.selectCrmExpertPoolList(crmExpertPool));
    }

    @GetMapping("/getExpertByName/{name}")
    public AjaxResult getExpertByName(@PathVariable String name){
        return AjaxResult.success(crmExpertPoolService.getExpertByName(name));
    }
}
